﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using PerCiGal.BPC;

namespace PerCiGal.WPFForm
{
    /// <summary>
    /// Logica di interazione per NewListWindow.xaml
    /// </summary>
    public partial class NewListWindow : Window
    {
        internal Types.COLLECTION Collection;

        public NewListWindow()
        {
            InitializeComponent();
        }

        //Create the collection
        private void btOK_Click(object sender, RoutedEventArgs e)
        {
            Types.COLLECTION_INFO collection_Info = new Types.COLLECTION_INFO();

            //Check if the list name not is empty
            if (string.IsNullOrEmpty(tbName.Text))
            {
                MessageBox.Show("Il nome della lista non può essere vuoto!", "Errore..", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            //Take the information from some control
            collection_Info.NAME = tbName.Text ;

            collection_Info.VERSION = Common.ProductVersion.Version;

            collection_Info.DT_CREATION = DateTime.UtcNow;

            collection_Info.DT_LAST_MODIFIED = DateTime.UtcNow;

            collection_Info.FILE_PATH = System.IO.Path.Combine(tbFolder.Text, tbName.Text + ".sdf");

            //Check if the password and the confirm password are the same
            if (pbPassword.Password == pbConfirm.Password)
            {
                if (!string.IsNullOrEmpty(pbPassword.Password))
                    collection_Info.PWD = pbPassword.Password;

                if (!string.IsNullOrEmpty(pbConfirm.Password))
                    collection_Info.PWD = pbConfirm.Password;
            }
            else
            {
                MessageBox.Show("Le password devo essere identiche!", "Errore..", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            //if (imgImage.Source != null)
            //    collection_Info.PICTURE = Common.FunctionImage.ByteArrayFromImage(imgImage.Source);

            BPC.BPCCollection collection = new BPC.BPCCollection();

            collection.Create(collection_Info);
        }

        private void btBrowse_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.FolderBrowserDialog folderdialog = new System.Windows.Forms.FolderBrowserDialog();

            if (folderdialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                tbFolder.Text = folderdialog.SelectedPath;
            }
        }
    }
}
